class ApplicationController < ActionController::Base
  protect_from_forgery
  
  helper_method :current_user, :current_admin, :current_supplier, :current_cart
  
  private
  
    def current_user
      @current_user ||= User.find(session[:user_id]) if session[:user_id]
    end
  
    def current_admin
      @current_admin ||= AdminUser.find(session[:admin_user_id]) if session[:admin_user_id]
    end
    
    def current_supplier
      @current_supplier ||= Supplier.find(session[:supplier_user_id]) if session[:supplier_user_id]
    end    
    
    def current_cart
      if session[:cart_id].nil?
        @cart = Cart.create
        @cart.save
        session[:cart_id] = @cart.id
        @cart
      else
        Cart.find(session[:cart_id])
      end
    end  
end
